import config from "../config";
import canvasAbstract from "./canvasAbstract";
import model from "../model/tank";
import position from "../service/position";
export default new class extends canvasAbstract implements ICanvas {
  name: string = "tank";
  life: number = 10;
  num(): number {
    return config.tank.num;
  }
  index: number = 0;
  model(): IModelConstructor {
    return model;
  }
  intervalId = 0;
  stop() {
    clearInterval(this.intervalId);
  }
  render(): void {
    this.createModels();
    this.renderModels();

    this.intervalId = setInterval(() => this.renderModels(), config.timeout);
  }

  public renderModels() {
    this.ctx.clearRect(0, 0, config.canvas.width, config.canvas.height);
    super.renderModels();
  }
  createModels(): void {
    for (let i = 0; i < this.num(); i++) {
      const pos = position.position();
      const model = this.model();
      const instance = new model(pos.x, 0);
      this.models.push(instance);
    }
  }
}("tank");
